package com.acwing.partition9;

import java.io.*;

/**
 * @author `RKC`
 * @date 2021/12/1 16:45
 */
public class AC896最长上升子序列II {

    private static final int N = 100010;
    private static int[] stk = new int[N];
    private static int n, top = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] ss = reader.readLine().split(" ");
        n = Integer.parseInt(ss[0]);
        ss = reader.readLine().split(" ");
        for (int i = 0; i < n; i++) {
            int h = Integer.parseInt(ss[i]);
            //二分找到第一个大于等于h的数
            int l = 0, r = top;
            while (l < r) {
                int mid = l + r >> 1;
                if (stk[mid] >= h) r = mid;
                else l = mid + 1;
            }
            if (l == top) top++;
            stk[l] = h;
        }
        writer.write(top + "\n");
        writer.flush();
    }
}
